<?php
namespace app\home\controller;
use app\home\model\Channel;
// use app\index\
class Page extends Base
{
    public function index()
    {   
        $id=request()->param('id');
        $article=db("channel_page");
        $channel=db("channel");
        $viewPage=$this->getIndexPage($id);
        $channelModel=new Channel();
        $fname=$channelModel->getFieldById($id,"name");  
        $p=request()->param('p'); 
        if(!$p){
            $p=1;
        }
        
        if($id){
            $mark=$channelModel->getMarkByid($id);
        }else{
            $mark="index";
        }
        $pid=$channelModel->getFieldById($id,"pid");
        if($pid > 0){
            $gcid=$pid;
            $pcid=$id;            
            $lchannel=$channelModel->getLeftChannel($gcid);
            $gnavName=$channelModel->getFieldById($gcid,"name");
            $pnavName=$channelModel->getFieldById($pcid,"name");
            // $channel->where("id=".$gcid)->value("name");         
            // $pnavName=$channel->where("id=".$pcid)->value("name");
        }else{
            $gcid=$id;
            $pcid=$channelModel->getIdByPid($id);
            $gnavName=$channelModel->getFieldById($gcid,"name");
            // $pcid=$channel->where("status=1 and pid=".$id)->order("sort asc ,id desc")->value("id");;
            // $lchannel=$channelModel->getLeftChannel($id);            
        }

        $where['status']=1;
        $where['cid']=$id;
        $mess=$article->where($where)->find();
        // SEO META关键字配置
        $meta=$this->getSeoMeta($gnavName,$pnavName,$mess);
        $this->assign("meta",$meta);

        
        $banner=$this->get_banner($gcid);
        
        $modelx=$channel->where("id",$id)->value("modelx");
        $modelxMark=db("modelx")->where("id=".$modelx)->value("mark");
        $this->assign("modelxMark",$modelxMark);
        
        $this->assign("banner",$banner);
        $this->assign("pnavName",$pnavName);
        $this->assign("gnavName",$gnavName);
        $this->assign("lchannel",$lchannel);
        $this->assign("cid",$cid);
        $this->assign("gcid",$gcid);
        $this->assign("pcid",$pcid);
        $this->assign("fname",$fname);
        $this->assign("mess",$mess);
		return view($viewPage);
    }
}
